import {
  setStorageToken,
  getStorageToken,
  removeStorageToken
} from '@/utils/storage'
import { UserInfo } from '@/api/user'

const state = {
  token: getStorageToken() || {},
  userInfo: {}
}
const mutations = {
  setToken(state, token) {
    state.token = token
    setStorageToken(token)
  },
  setUserInfo(state, obj) {
    state.userInfo = obj
  },
  removeToken(state) {
    state.token = ''
    removeStorageToken()
  }
}
const actions = {
  async ActionsUserInfo(context) {
    const res = await UserInfo()
    console.log('个人资料', res)
    context.commit('setUserInfo', res.data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
